<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><title>WebAPIs学习笔记 | XC's Blog</title><meta name="keywords" content="Web APIs笔记"><meta name="author" content="XC's Blog"><meta name="copyright" content="XC's Blog"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="WebAPIs基本学习笔记 作用：使用JS操作html和浏览器 分类：DOM（文档对象模型）、BOM（浏览器对象模型）     DOM的内容 DOM（Document Object Model——文档对象模型）是用来呈现以及与任意 HTML 或 XML文档交互的API 简单来说：DOM是浏览器提供的一套专门用来 操作网页内容 的功能 作用：开发网页内容特效和实现用户交互  DOM树 内容：将HTM"><meta property="og:type" content="article"><meta property="og:title" content="WebAPIs学习笔记"><meta property="og:url" content="https://www.webxc.ml/post/sr32/index.html"><meta property="og:site_name" content="XC&#39;s Blog"><meta property="og:description" content="WebAPIs基本学习笔记 作用：使用JS操作html和浏览器 分类：DOM（文档对象模型）、BOM（浏览器对象模型）     DOM的内容 DOM（Document Object Model——文档对象模型）是用来呈现以及与任意 HTML 或 XML文档交互的API 简单来说：DOM是浏览器提供的一套专门用来 操作网页内容 的功能 作用：开发网页内容特效和实现用户交互  DOM树 内容：将HTM"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg"><meta property="article:published_time" content="2023-03-14T18:00:00.000Z"><meta property="article:modified_time" content="2023-05-04T17:24:22.255Z"><meta property="article:author" content="XC&#39;s Blog"><meta property="article:tag" content="Web APIs笔记"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg"><link rel="shortcut icon" href="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><link rel="canonical" href="https://www.webxc.ml/post/sr32/"><link rel="preconnect" href="//cdn.jsdelivr.net"><link rel="preconnect" href="//busuanzi.ibruce.info"><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://npm.elemecdn.com/@fortawesome/fontawesome-free@6.2.0/css/all.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/node-snackbar/dist/snackbar.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/@fancyapps/ui/dist/fancybox.css" media="print" onload='this.media="all"'><script>const GLOBAL_CONFIG={root:"/",algolia:void 0,localSearch:{path:"/search.xml",preload:!1,languages:{hits_empty:"找不到您查询的内容：${query}"}},translate:void 0,noticeOutdate:void 0,highlight:{plugin:"highlighjs",highlightCopy:!0,highlightLang:!0,highlightHeightLimit:!1},copy:{success:"吾辈宣布,你的剪切板已被占领",error:"呀~复制失败,请在尝试下",noSupport:"对不起,你的浏览器不支持"},relativeDate:{homepage:!1,post:!1},runtime:"",date_suffix:{just:"刚刚",min:"分钟前",hour:"小时前",day:"天前",month:"个月前"},copyright:{limitCount:60,languages:{author:"作者: XC's Blog",link:"链接: ",source:"来源: XC's Blog",info:"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},lightbox:"fancybox",Snackbar:{chs_to_cht:"您已切换为繁体",cht_to_chs:"您已切换为简体",day_to_night:"您已切换为深色主题",night_to_day:"您已切换为浅色主题",bgLight:"#3b70fc",bgDark:"#121212",position:"bottom-center"},source:{justifiedGallery:{js:"https://npm.elemecdn.com/flickr-justified-gallery/dist/fjGallery.min.js",css:"https://npm.elemecdn.com/flickr-justified-gallery/dist/fjGallery.css"}},isPhotoFigcaption:!1,islazyload:!0,isAnchor:!0}</script><script id="config-diff">var GLOBAL_CONFIG_SITE={title:"WebAPIs学习笔记",isPost:!0,isHome:!1,isHighlightShrink:!1,isToc:!0,postUpdate:"2023-05-04 17:24:22"}</script><noscript><style>#nav{opacity:1}.justified-gallery img{opacity:1}#post-meta time,#recent-posts time{display:inline!important}</style></noscript><script>(e=>{e.saveToLocal={set:function(e,t,o){if(0===o)return;const n=864e5*o,a={value:t,expiry:(new Date).getTime()+n};localStorage.setItem(e,JSON.stringify(a))},get:function(e){const t=localStorage.getItem(e);if(!t)return;const o=JSON.parse(t);if(!((new Date).getTime()>o.expiry))return o.value;localStorage.removeItem(e)}},e.getScript=e=>new Promise(((t,o)=>{const n=document.createElement("script");n.src=e,n.async=!0,n.onerror=o,n.onload=n.onreadystatechange=function(){const e=this.readyState;e&&"loaded"!==e&&"complete"!==e||(n.onload=n.onreadystatechange=null,t())},document.head.appendChild(n)})),e.activateDarkMode=function(){document.documentElement.setAttribute("data-theme","dark"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#0d0d0d")},e.activateLightMode=function(){document.documentElement.setAttribute("data-theme","light"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#ffffff")};const t=saveToLocal.get("theme");"dark"===t?activateDarkMode():"light"===t&&activateLightMode();const o=saveToLocal.get("aside-status");void 0!==o&&("hide"===o?document.documentElement.classList.add("hide-aside"):document.documentElement.classList.remove("hide-aside"));/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)&&document.documentElement.classList.add("apple")})(window)</script><link rel="stylesheet" href="https://cdn1.tianli0.top/gh/web-xc/My-blog-CSS/mgi.css"><link rel="stylesheet" href="https://cdn1.tianli0.top/gh/web-xc/My-blog-CSS/mg111.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.16/css/mg2.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/styless.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/styles.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/font.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.15/css/font2.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiperstyle.css" media="print" onload='this.media="all"'><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="avatar"></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">74</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">22</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><hr><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-shouye"></i> <span>首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-shijian"></i> <span>时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian"></i> <span>标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw iconfont icon-fenlei"></i> <span>分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-lianxiwomen"></i> <span>友联</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-iconzhengli-"></i> <span>关于</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw iconfont icon-a-wangzhanchaojilianjiehulianwang"></i> <span>推荐</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="http://www.inode.club/"><i class="fa-fw fa-sharp fa-solid fa-square-rss"></i> <span>程序员指南</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="http://ife.baidu.com/"><i class="fa-fw fa-brands fa-vuejs"></i> <span>前端技术学园</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.yuque.com/tademanong/ag7q4n"><i class="fa-fw fa-solid fa-users"></i> <span>前端技术圈</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.code-nav.cn/"><i class="fa-fw fa-solid fa-shop"></i> <span>编程导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://q.shanyue.tech/"><i class="fa-fw fa-brands fa-square-js"></i> <span>每日一题</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://fanyouf.gitee.io/u1word/#/h5"><i class="fa-fw fa-solid fa-headphones"></i> <span>前端必会单词</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://site.51git.cn/render/gonav/4.html"><i class="fa-fw iconfont icon-wangzhandingzhi"></i> <span>网址导航</span></a></li><li><a class="site-page child" href="https://www.webxc.ml/music/"><i class="fa-fw iconfont icon-musical-note"></i> <span>音乐解锁</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image:url('https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg')"><nav id="nav"><span id="blog_name"><div class="back-home-button" tabindex="-1"><i class="back-home-button-icon fas fa-grip-vertical"></i><div class="back-menu-list-groups"><div class="back-menu-list-group"><div class="back-menu-list-title">项目</div><div class="back-menu-list"><a class="back-menu-item" href="/" title="前往博客主页" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">主站</span></a><a class="back-menu-item" href="https://e.webxc.tk/" rel="external nofollow" title="前往学习笔记" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">学习笔记</span></a><a class="back-menu-item" href="https://v.webxc.tk/" rel="external nofollow" title="VuePress学习文档" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">VuePress文档</span></a><a class="back-menu-item" href="https://b.webxc.tk/" rel="external nofollow" title="旧站Hexo" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">旧站Hexo</span></a><a class="back-menu-item" href="https://gridea.webxc.ml/" rel="external nofollow" title="Gridea笔记" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Gridea笔记</span></a><a class="back-menu-item" href="https://c.webxc.tk/" rel="external nofollow" title="魔改Hexo" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">魔改Hexo</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">博客镜像</div><div class="back-menu-list"><a class="back-menu-item" href="https://blog.webxc.ml/" title="Vercel镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Vercel镜像</span></a><a class="back-menu-item" href="https://webxc.tk/" title="Netlify镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Netlify镜像</span></a><a class="back-menu-item" href="https://web-xc.gitee.io/" title="Gitee镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Gitee镜像</span></a><a class="back-menu-item" href="https://cf.webxc.ml/" title="Cloudflare镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Cloudflare镜像</span></a><a class="back-menu-item" href="https://render.webxc.ml/" title="Render镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Render镜像</span></a></div></div></div></div><a id="site-name" href="/"><div class="title">XC's Blog</div><i class="fa-solid fa-house"></i></a></span><div class="mask-name-container"><center id="name-container"><a id="page-name" href="javascript:btf.scrollToDest(0, 500)">PAGE_NAME</a></center></div><div id="menus"><div class="nav-button" id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i> <span>搜索</span></a></div><div class="nav-button" id="darkmode_navswitch"><a class="darkmode_switchbutton" type="button" title="浅色和深色模式转换" onclick="switchDarkMode()"><i class="fas fa-adjust"></i></a></div><div class="nav-button" id="nav-totop"><a class="totopbtn"><i class="fas fa-arrow-up"></i><span id="percent" onclick="btf.scrollToDest(0,500)">0</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-shouye"></i> <span>首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-shijian"></i> <span>时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian"></i> <span>标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw iconfont icon-fenlei"></i> <span>分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-lianxiwomen"></i> <span>友联</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-iconzhengli-"></i> <span>关于</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw iconfont icon-a-wangzhanchaojilianjiehulianwang"></i> <span>推荐</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="http://www.inode.club/"><i class="fa-fw fa-sharp fa-solid fa-square-rss"></i> <span>程序员指南</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="http://ife.baidu.com/"><i class="fa-fw fa-brands fa-vuejs"></i> <span>前端技术学园</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.yuque.com/tademanong/ag7q4n"><i class="fa-fw fa-solid fa-users"></i> <span>前端技术圈</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.code-nav.cn/"><i class="fa-fw fa-solid fa-shop"></i> <span>编程导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://q.shanyue.tech/"><i class="fa-fw fa-brands fa-square-js"></i> <span>每日一题</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://fanyouf.gitee.io/u1word/#/h5"><i class="fa-fw fa-solid fa-headphones"></i> <span>前端必会单词</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://site.51git.cn/render/gonav/4.html"><i class="fa-fw iconfont icon-wangzhandingzhi"></i> <span>网址导航</span></a></li><li><a class="site-page child" href="https://www.webxc.ml/music/"><i class="fa-fw iconfont icon-musical-note"></i> <span>音乐解锁</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">WebAPIs学习笔记</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-03-14T18:00:00.000Z" title="发表于 2023-03-14 18:00:00">2023-03-14</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-05-04T17:24:22.255Z" title="更新于 2023-05-04 17:24:22">2023-05-04</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Web-APIs%E7%AC%94%E8%AE%B0/">Web APIs笔记</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span data-flag-title="WebAPIs学习笔记"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="twikoo_visitors"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="WebAPIs基本学习笔记"><a href="#WebAPIs基本学习笔记" class="headerlink" title="WebAPIs基本学习笔记"></a>WebAPIs基本学习笔记</h2><ul><li>作用：使用JS操作html和浏览器</li><li>分类：DOM（文档对象模型）、BOM（浏览器对象模型）</li></ul><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220626113415737.png" style="zoom:33%"><h2 id="DOM的内容"><a href="#DOM的内容" class="headerlink" title="DOM的内容"></a>DOM的内容</h2><ul><li>DOM（Document Object Model——文档对象模型）是用来呈现以及与任意 HTML 或 XML文档交互的API</li><li>简单来说：DOM是浏览器提供的一套专门用来 操作网页内容 的功能</li><li>作用：开发网页内容特效和实现用户交互</li></ul><h2 id="DOM树"><a href="#DOM树" class="headerlink" title="DOM树"></a>DOM树</h2><ul><li><p>内容：将HTML以树状的内容直观显示出来，也称文档树</p></li><li><p>作用：直观体现出标签与标签的关系</p></li></ul><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;X-UA-Compatible&quot;</span> <span class="attr">content</span>=<span class="string">&quot;IE=edge&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>Document<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    文本</span><br><span class="line">    <span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">&quot;&quot;</span>&gt;</span>链接<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">h1</span> <span class="attr">class</span>=<span class="string">&quot;&quot;</span> <span class="attr">id</span>=<span class="string">&quot;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/0d429a429c4b10f6ba024de35a73da88b39e4b6e76b0f7bd95697db1ceaab0b5.gif" style="zoom:33%"><h2 id="获取DOM元素"><a href="#获取DOM元素" class="headerlink" title="获取DOM元素"></a>获取DOM元素</h2><ul><li><p>CSS选择器 匹配到第一个元素，返回一个HTMLElement对象</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法</span></span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;CSS选择器&#x27;</span>)</span><br></pre></td></tr></table></figure></li><li><p>匹配多个选择器，返回NodeList对象集合，得到是一个伪数组</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">document</span>.<span class="title function_">querySelectorAll</span>(<span class="string">&#x27;CSS选择器&#x27;</span>)</span><br></pre></td></tr></table></figure></li><li><p>其他方法</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">document</span>.<span class="title function_">getElementByid</span>(<span class="string">&#x27;id名&#x27;</span>)</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">getElementByTagName</span>(<span class="string">&#x27;标签名&#x27;</span>)</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">getElementByClassName</span>(<span class="string">&#x27;类名&#x27;</span>)</span><br></pre></td></tr></table></figure></li></ul><h2 id="设置和修改DOM元素"><a href="#设置和修改DOM元素" class="headerlink" title="设置和修改DOM元素"></a>设置和修改DOM元素</h2><ul><li><p>修改标签文本内容</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法：</span></span><br><span class="line">元素.<span class="property">innerText</span>=<span class="string">&#x27;&#x27;</span> </span><br><span class="line"><span class="comment">//只能识别内容，不能解释标签</span></span><br><span class="line"><span class="comment">//可以解析标签 即：</span></span><br><span class="line">元素.<span class="property">innerHTML</span>=<span class="string">&#x27;&lt;h3&gt;会对html标签进行解析&lt;/h3&gt;&#x27;</span> </span><br></pre></td></tr></table></figure></li></ul><h2 id="设置与修改DOM元素的属性"><a href="#设置与修改DOM元素的属性" class="headerlink" title="设置与修改DOM元素的属性"></a>设置与修改DOM元素的属性</h2><ul><li><p>语法：<code>对象.属性=值</code>，最常见的属性比如： <strong>href</strong>、<strong>title</strong>、<strong>src</strong> 等</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//例子</span></span><br><span class="line"><span class="keyword">let</span> pic =<span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;img&#x27;</span>)</span><br><span class="line">pic.<span class="property">src</span>=<span class="string">&#x27;./images/pic2.jpg&#x27;</span></span><br></pre></td></tr></table></figure></li><li><p>通过<strong>style</strong>修改CSS属性</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> box =<span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;div&#x27;</span>)</span><br><span class="line">box.<span class="property">style</span>.<span class="property">width</span>=<span class="string">&#x27;300px&#x27;</span></span><br><span class="line">box.<span class="property">style</span>.<span class="property">paddingLeft</span> =<span class="string">&#x27;300px&#x27;</span></span><br><span class="line"><span class="comment">//注：有链接-符号的需要转换为小驼峰命名法</span></span><br><span class="line"><span class="comment">//即：padding-left--&gt;paddingLeft</span></span><br></pre></td></tr></table></figure></li><li><p>修改标签类名</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">元素.<span class="property">clssName</span>=<span class="string">&#x27;新类名&#x27;</span></span><br><span class="line"><span class="comment">//注：直接使用 className 赋值会覆盖以前的类名</span></span><br><span class="line"><span class="comment">//保留可写</span></span><br><span class="line">元素.<span class="property">clssName</span>=<span class="string">&#x27;旧类名 新类名&#x27;</span></span><br></pre></td></tr></table></figure></li><li><p>通过<strong>clssList</strong>操作css类名</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//增加一个类名</span></span><br><span class="line">元素.<span class="property">classList</span>.<span class="title function_">add</span>(<span class="string">&#x27;类名&#x27;</span>)</span><br><span class="line"><span class="comment">//删除一个类</span></span><br><span class="line">元素.<span class="property">classList</span>.<span class="title function_">remove</span>(<span class="string">&#x27;类名&#x27;</span>)</span><br><span class="line"><span class="comment">//切换一个类,存在就删除,不存在就增加</span></span><br><span class="line">元素.<span class="property">classList</span>.<span class="title function_">toggle</span>(<span class="string">&#x27;类名&#x27;</span>)</span><br></pre></td></tr></table></figure></li></ul><h2 id="修改表单属性"><a href="#修改表单属性" class="headerlink" title="修改表单属性"></a>修改表单属性</h2><ul><li><p>作用：表单很多情况，也需要修改属性，比如点击眼睛，可以看到密码，本质是把表单类型转换为文本框</p></li><li><p>获取：DOM对象.属性名；设置：DOM对象.属性名&#x3D;新值</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">表单.<span class="property">value</span>=<span class="string">&#x27;用户名&#x27;</span></span><br><span class="line">表单.<span class="property">type</span>=<span class="string">&#x27;password&#x27;</span></span><br></pre></td></tr></table></figure></li><li><p>表单属性中添加就有效果,移除就没有效果,一律使用布尔值表示 如果为true 代表添加了该属性 如果是false 代表移除了该属性<br>比如： disabled、checked、selected</p></li></ul><h2 id="定时器-setInterval-间歇函数"><a href="#定时器-setInterval-间歇函数" class="headerlink" title="定时器-setInterval() 间歇函数"></a>定时器-<strong>setInterval()</strong> 间歇函数</h2><ul><li><p>开启定时器</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">setInterval</span>(函数，间隔时间) <span class="comment">//时间也毫秒为单位，1秒==1000ms</span></span><br></pre></td></tr></table></figure></li><li><p>关闭定时器</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> timer =<span class="built_in">setInterval</span>(函数，间隔时间)</span><br><span class="line"><span class="built_in">clearInterval</span>(timer)</span><br></pre></td></tr></table></figure></li></ul><hr><h2 id="事件"><a href="#事件" class="headerlink" title="事件"></a>事件</h2><blockquote><p>事件是在编程时系统内发生的动作或者发生的事情，比如用户在网页上单击一个按钮</p></blockquote><h3 id="事件监听"><a href="#事件监听" class="headerlink" title="事件监听"></a>事件监听</h3><blockquote><p>让程序检测是否有事件产生，一旦有事件触发，就立即调用一个函数做出响应，也称为 注册事件</p></blockquote><p>语法：<code>元素.addEventListener(&#39;事件&#39;,要执行的函数)</code></p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//获取元素</span></span><br><span class="line"><span class="keyword">let</span> btn=<span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;button&#x27;</span>)</span><br><span class="line"><span class="comment">//事件监听</span></span><br><span class="line">btn.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>,<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="title function_">alert</span>(<span class="string">&#x27;被点击了&#x27;</span>)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure><p>事件监听三要素：</p><ul><li>事件源：那个dom元素被事件触发了，要获取dom元素</li><li>事件：有什么方式触发，比如鼠标点击<strong>click</strong></li><li>事件触发时调用的函数</li></ul><h3 id="版本"><a href="#版本" class="headerlink" title="版本"></a>版本</h3><ul><li><p>DOM L0</p><p>语法：<code>事件源.on事件=function()&#123;&#125;</code></p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">btn.<span class="property">onclick</span>=<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">   <span class="title function_">alert</span>(<span class="string">&#x27;点击&#x27;</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li><li><p>DOM L2 :star:</p><p>语法：<code>事件源.addEventlistener(事件，事件处理函数)</code></p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">btn.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>,<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="title function_">alert</span>(<span class="string">&#x27;点击&#x27;</span>)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></li></ul><h3 id="事件类型"><a href="#事件类型" class="headerlink" title="事件类型"></a>事件类型</h3><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220702092821996.png" style="zoom:33%"><hr><h2 id="高阶函数"><a href="#高阶函数" class="headerlink" title="高阶函数"></a>高阶函数</h2><blockquote><p>高阶函数可以被简单理解为函数的高级应用，JavaScript 中函数可以被当成【值】来对待，基于这个特性实现函数的高级应用</p></blockquote><h3 id="函数表达式"><a href="#函数表达式" class="headerlink" title="函数表达式"></a>函数表达式</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> counter=<span class="keyword">function</span>(<span class="params">x,y</span>)&#123;</span><br><span class="line">    <span class="keyword">return</span> x+y</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//调用</span></span><br><span class="line"><span class="keyword">let</span> result=<span class="title function_">counter</span>(<span class="number">1</span>,<span class="number">2</span>)</span><br></pre></td></tr></table></figure><h3 id="回调函数"><a href="#回调函数" class="headerlink" title="回调函数"></a>回调函数</h3><blockquote><p>如果将函数A当作参数传递给函数B时，我们称函数A为回调函数</p><p>回调函数本质还是函数，只不过把它当成参数使用</p></blockquote><p>使用场景</p><ul><li><p>定时器<strong>setInterval()</strong> 间歇函数</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">fn</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="title function_">alert</span>(<span class="string">&#x27;我是回调函数&#x27;</span>)</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//fn传递了给setInterval ，fn就是回调函数</span></span><br><span class="line"><span class="built_in">setInterval</span>(fn,<span class="number">1000</span>)</span><br></pre></td></tr></table></figure></li><li><p>事件监听</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">btn.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>,<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">     <span class="title function_">alert</span>(<span class="string">&#x27;我是回调函数&#x27;</span>)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></li></ul><hr><h2 id="环境变量"><a href="#环境变量" class="headerlink" title="环境变量"></a>环境变量</h2><blockquote><p>环境对象指的是函数内部特殊的变量 this ，它代表着当前函数运行时所处的环境<br>作用：弄清楚this的指向，可以让我们代码更简洁</p></blockquote><ul><li>函数的调用方式不同，this 指代的对象也不同</li><li>【谁调用， this 就是谁】 是判断 this 指向的粗略规则</li><li>直接调用函数，其实相当于是 window.函数，所以 this 指代 window</li></ul><hr><h2 id="编程思想"><a href="#编程思想" class="headerlink" title="编程思想"></a>编程思想</h2><h3 id="排他思想"><a href="#排他思想" class="headerlink" title="排他思想"></a>排他思想</h3><p>当前元素为A状态,其他元素为B状态</p><p>使用：</p><ol><li>干掉所有人<br>使用for循环</li><li>复活他自己<br>通过this或者下标找到自己或者对应的元素</li></ol><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//给点击的li加上pink类</span></span><br><span class="line">&lt;li <span class="keyword">class</span>=<span class="string">&#x27;pink&#x27;</span>&gt;第一个&lt;/li&gt;</span><br><span class="line">   <span class="language-xml"><span class="tag">&lt;<span class="name">li</span>&gt;</span>第二个<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span></span><br><span class="line">   <span class="language-xml"><span class="tag">&lt;<span class="name">li</span>&gt;</span>第三个<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span></span><br><span class="line"> 	 <span class="keyword">let</span> lis = <span class="variable language_">document</span>.<span class="title function_">querySelectorAll</span>(<span class="string">&#x27;li&#x27;</span>)</span><br><span class="line">   <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i &lt; lis.<span class="property">length</span>; i++) &#123;</span><br><span class="line">           lis[i].<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">             <span class="comment">// 干掉所有人</span></span><br><span class="line">              <span class="keyword">for</span> (<span class="keyword">let</span> j = <span class="number">0</span>; j &lt; btns.<span class="property">length</span>; j++) &#123;</span><br><span class="line">                 btns[j].<span class="property">classList</span>.<span class="title function_">remove</span>(<span class="string">&#x27;pink&#x27;</span>)</span><br><span class="line">              &#125;</span><br><span class="line">               <span class="comment">//复活自己</span></span><br><span class="line">                <span class="variable language_">this</span>.<span class="property">classList</span>.<span class="title function_">add</span>(<span class="string">&#x27;pink&#x27;</span>)</span><br><span class="line">               <span class="comment">//==================分割线===========================</span></span><br><span class="line">               <span class="comment">//高级做法</span></span><br><span class="line">               <span class="comment">// 我只需要找出那个唯一的 pink类，删除</span></span><br><span class="line">               <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.pink&#x27;</span>).<span class="property">classList</span>.<span class="title function_">remove</span>(<span class="string">&#x27;pink&#x27;</span>)</span><br><span class="line">               <span class="comment">// 我的</span></span><br><span class="line">               <span class="variable language_">this</span>.<span class="property">classList</span>.<span class="title function_">add</span>(<span class="string">&#x27;pink&#x27;</span>)</span><br><span class="line">           &#125;)</span><br><span class="line">       &#125;</span><br></pre></td></tr></table></figure><hr><h2 id="DOM结点"><a href="#DOM结点" class="headerlink" title="DOM结点"></a>DOM结点</h2><blockquote><p>DOM树里每一个内容都称之为节点</p></blockquote><p>结点类型</p><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220702101440879.png" style="zoom:33%"><ul><li><p>元素结点 :star:</p><p>所有的标签：比如 <code>body</code> <code>div</code>，<code>html</code>是根节点</p></li><li><p>属性结点</p><p>所有的属性，比如 <code>herf</code></p></li><li><p>文本结点</p><p>所有的文本</p></li></ul><h3 id="结点的查找"><a href="#结点的查找" class="headerlink" title="结点的查找"></a>结点的查找</h3><p>结点的关系：父节点，子节点，兄弟节点</p><ul><li><p>父节点的查找</p><p>使用<code>parentNode</code>属性，返回最近一级的父节点，找不到返回<strong>null</strong></p><p>语法：<code>子元素.parentNode</code></p></li><li><p>子结点的查找</p><p><code>childNodes</code> - 获得所有的子节点，包括文本节点（空格、换行）、注释节点等</p><p><code>chilrden</code> :star: -获得所有元素节点，返回的还是一个伪数组</p></li><li><p>兄弟结点的查找</p><p><code>nextElementSibling</code> 查找下一个兄弟结点</p><p><code>previousElementSibling</code> 查找上一个兄弟节点</p></li></ul><h3 id="结点的增加"><a href="#结点的增加" class="headerlink" title="结点的增加"></a>结点的增加</h3><blockquote><p>一般情况下，我们新增节点，按照如下操作</p><p>1创建一个新的节点</p><p>2把创建的新的节点放入到指定的元素内部</p></blockquote><ul><li><p>创建结点</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">documnet.<span class="title function_">createElement</span>(<span class="string">&#x27;标签名&#x27;</span>)</span><br></pre></td></tr></table></figure></li><li><p>追加结点</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//插入父元素的最后</span></span><br><span class="line">父元素.<span class="title function_">appendChild</span>(要插入的元素)</span><br><span class="line"><span class="comment">//插到某个子元素的前面</span></span><br><span class="line">父元素.<span class="title function_">insertBefore</span>(要插入的元素,在哪个元素的前面)</span><br></pre></td></tr></table></figure></li></ul><h3 id="结点的克隆"><a href="#结点的克隆" class="headerlink" title="结点的克隆"></a>结点的克隆</h3><blockquote><p>cloneNode会克隆出一个跟原标签一样的元素，括号内传入布尔值<br>若为true，则代表克隆时会包含后代节点一起克隆<br>若为false，则代表克隆时不包含后代节点<br>默认为false</p></blockquote><p><strong>语法</strong>：<code>元素.cloneNode(布尔值)</code></p><h3 id="结点的删除"><a href="#结点的删除" class="headerlink" title="结点的删除"></a>结点的删除</h3><blockquote><p>删除节点和隐藏节点（display:none） 有区别的： 隐藏节点还是存在的，但是删除，则从html中删除节点在 JavaScript 原生DOM操作中，要删除元素必须通过父元素删除</p></blockquote><p><strong>语法</strong>：<code>父元素.removeChild(要删除的元素)</code></p><hr><h2 id="重绘和回流"><a href="#重绘和回流" class="headerlink" title="重绘和回流"></a>重绘和回流</h2><p>浏览器进行界面渲染</p><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220702104807814.png" style="zoom:33%"><ul><li>解析（Parser）HTML，生成DOM树(DOM Tree)</li><li>同时解析（Parser） CSS，生成样式规则 (Style Rules)</li><li>根据DOM树和样式规则，生成渲染树(Render Tree)</li><li>进行布局 Layout(回流&#x2F;重排):根据生成的渲染树，得到节点的几何信息（位置，大小）</li><li>进行绘制 Painting(重绘): 根据计算和获取的信息进行整个页面的绘制</li><li>Display: 展示在页面上</li></ul><h3 id="回流-重排"><a href="#回流-重排" class="headerlink" title="回流(重排)"></a>回流(重排)</h3><blockquote><p>当 Render Tree 中部分或者全部元素的尺寸、结构、布局等发生改变时，浏览器就会重新渲染部分或全部文档的过程称为回流，简单理解影响到布局了，就会有回流</p></blockquote><p>会导致回流的操作</p><ul><li>页面的首次刷新</li><li>浏览器的窗口大小发生改变</li><li>元素的大小或位置发生改变</li><li>改变字体的大小</li><li>内容的变化（如：input框的输入，图片的大小）</li><li>激活css伪类 （如：:hover）</li><li>脚本操作DOM（添加或者删除可见的DOM元素）</li></ul><h3 id="重绘"><a href="#重绘" class="headerlink" title="重绘"></a>重绘</h3><blockquote><p>由于节点(元素)的样式的改变并不影响它在文档流中的位置和文档布局时(比如：color、background-color、<br>outline等), 称为重绘</p></blockquote><p><strong>注：</strong>重绘不一定引起回流，而回流一定会引起重绘。</p><p>练习：</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> s = <span class="variable language_">document</span>.<span class="property">body</span>.<span class="property">stlye</span></span><br><span class="line">s.<span class="property">padding</span> = <span class="string">&#x27;2px&#x27;</span> <span class="comment">//重排 + 重绘</span></span><br><span class="line">s.<span class="property">border</span> = <span class="string">&#x27;1px solid red&#x27;</span> <span class="comment">// 重排 + 重绘</span></span><br><span class="line">s.<span class="property">color</span> = <span class="string">&#x27;red&#x27;</span><span class="comment">//重绘</span></span><br><span class="line">s.<span class="property">backgroundColor</span> = <span class="string">&#x27;#666&#x27;</span> <span class="comment">//重绘</span></span><br><span class="line">s.<span class="property">fontSize</span>= <span class="string">&quot;14px&quot;</span> <span class="comment">// 重排 + 重绘</span></span><br></pre></td></tr></table></figure><hr><h2 id="事件高级"><a href="#事件高级" class="headerlink" title="事件高级"></a>事件高级</h2><h3 id="事件对象"><a href="#事件对象" class="headerlink" title="事件对象"></a>事件对象</h3><blockquote><p>内容：事件对象是个对象，这个对象里有事件触发时的相关信息</p><p>例如：鼠标点击事件中，事件对象就存了鼠标点在哪个位置等信息</p></blockquote><p>获取方法：</p><ul><li><p>在事件绑定的回调函数的第一个参数就是事件对象</p></li><li><p>一般命名为 even 、ev 、e</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">元素.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>,<span class="keyword">function</span>(<span class="params">e</span>)&#123;</span><br><span class="line">    <span class="comment">//e就是事件对象</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></li></ul><p>常用事件对象的属性</p><ul><li><code>type</code> ：获取当前事件类型</li><li><code>clientX</code> &#x2F; <code>clientY</code> ：获得光标相对于浏览器可见窗口左上角的位置</li><li><code>offsetX</code> &#x2F; <code>offsetY</code> : 获取光标相对于当前DOM元素左上角的位置</li><li><code>key</code> ：用户按下的键盘的值，现在不提倡用 <strong>keyCode</strong></li></ul><h3 id="事件流"><a href="#事件流" class="headerlink" title="事件流"></a>事件流</h3><blockquote><p>事件流指的是事件完整执行过程的流动路径，两个阶段：事件捕获和事件冒泡</p></blockquote><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220703184458601.png" style="zoom:33%"><ul><li><p>说明：假设页面里有个div，当触发事件时，会经历两个阶段，分别是捕获阶段、冒泡阶段</p></li><li><p>简单来说：捕获阶段是 从父到子 冒泡阶段是从子到父</p></li></ul><p><strong>事件冒泡</strong></p><blockquote><p>当一个元素的事件被触发时，同样的事件将会在该元素的所有祖先元素中依次被触发</p><p>简单理解：当一个元素触发事件后，会依次向上调用所有父级元素的同名事件</p><p>事件冒泡是默认存在的</p></blockquote><p><strong>事件捕获</strong></p><blockquote><p>从DOM的根元素开始去执行对应的事件 (从外到里)</p></blockquote><p>说明：</p><ul><li>addEventListener第三个参数传入true代表是捕获阶段触发（很少使用）</li><li>若传入false代表冒泡阶段触发，默认就是false</li><li>若是用 L0 事件监听，则只有冒泡阶段，没有捕获</li></ul><p><strong>阻止事件流动</strong></p><ul><li>因为默认就有冒泡模式的存在，所以容易导致事件影响到父级元素</li><li>若想把事件就限制在当前元素内，就需要阻止事件流动</li><li>阻止事件流动需要拿到事件对象</li><li>语法：<code>事件对象.stopProagation()</code></li><li>此方法可以阻断事件流动传播，不光在冒泡阶段有效，捕获阶段也有效</li></ul><p><strong>鼠标经过事件</strong>：</p><ul><li><p><code>mouseover</code> 和 <code>mouseout</code> 会有冒泡效果</p></li><li><p><code>mouseenter</code> 和 <code>mouseleave</code> 没有冒泡效果(推荐)</p></li></ul><p><strong>两种注册事件的区别：</strong></p><ul><li><p>传统on注册（L0）</p><ul><li>同一个对象,后面注册的事件会覆盖前面注册(同一个事件)</li><li>直接使用null覆盖偶就可以实现事件的解绑</li><li>都是冒泡阶段执行的</li></ul></li><li><p>事件监听注册（L2）</p><ul><li><p>语法: addEventListener(事件类型, 事件处理函数, 是否使用捕获)</p></li><li><p>后面注册的事件不会覆盖前面注册的事件(同一个事件)</p></li><li><p>可以通过第三个参数去确定是在冒泡或者捕获阶段执行</p></li><li><p>必须使用removeEventListener(事件类型, 事件处理函数, 获取捕获或者冒泡阶段)</p></li><li><p>匿名函数无法被解绑</p></li></ul></li></ul><h3 id="事件委托"><a href="#事件委托" class="headerlink" title="事件委托"></a>事件委托</h3><blockquote><p>事件委托其实是利用事件冒泡的特点， 给父元素添加事件，子元素可以触发</p></blockquote><ul><li><p><strong>优点：</strong>给父级元素加事件（可以提高性能）</p></li><li><p><strong>实现：</strong><code>事件对象.target</code> 可以获得真正触发事件的元素</p></li></ul><hr><h2 id="滚动事件"><a href="#滚动事件" class="headerlink" title="滚动事件"></a>滚动事件</h2><blockquote><p>作用：很多网页需要检测用户把页面滚动到某个区域后做一些处理， 比如固定导航栏，比如返回顶部</p></blockquote><p><strong>事件名</strong> <code>scroll</code></p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//可以给window或document添加滚动事件来监听整个页面</span></span><br><span class="line"><span class="variable language_">window</span>.<span class="title function_">addEventListener</span>(<span class="string">&#x27;scroll&#x27;</span>,<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="comment">//要执行的操作</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure><h2 id="加载事件"><a href="#加载事件" class="headerlink" title="加载事件"></a>加载事件</h2><h3 id="load-事件"><a href="#load-事件" class="headerlink" title="load 事件"></a>load 事件</h3><ul><li><p>加载外部资源（如图片、外联CSS和JavaScript等）加载完毕时触发的事件</p></li><li><p>为什么要学？</p><ul><li>有些时候需要等页面资源全部处理完了做一些事情</li><li>老代码喜欢把 script 写在 head 中，这时候直接找 dom 元素找不到</li></ul></li><li><p>事件名：<code>load</code></p></li><li><p>监听页面所有资源加载完毕：</p><ul><li><p>给 window 添加 load 事件</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">window</span>.<span class="title function_">addEventListener</span>(<span class="string">&#x27;load&#x27;</span>,<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="comment">//要执行的操作</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></li></ul></li><li><p>注意：不光可以监听整个页面资源加载完毕，也可以针对某个资源绑定load事件</p></li></ul><h3 id="DOMContentLoaded"><a href="#DOMContentLoaded" class="headerlink" title="DOMContentLoaded"></a>DOMContentLoaded</h3><ul><li><p>当初始的 HTML 文档被完全加载和解析完成之后，DOMContentLoaded 事件被触发，而<strong>无</strong>需等待样式表全加载</p></li><li><p>事件名：<code>DOMContentLoaded</code></p></li><li><p>监听页面DOM加载完毕：</p><ul><li><p>给 document 添加 DOMContentLoaded 事件</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">document</span>.<span class="title function_">addEventListener</span>(<span class="string">&#x27;DOMContentLoaded&#x27;</span>,<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="comment">//要执行的操作</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></li></ul></li></ul><hr><h2 id="元素大小和位置"><a href="#元素大小和位置" class="headerlink" title="元素大小和位置"></a>元素大小和位置</h2><p><strong>三大家族</strong></p><ul><li>scroll家族</li><li>offest家族</li><li>client家族</li></ul><h3 id="scroll家族"><a href="#scroll家族" class="headerlink" title="scroll家族"></a>scroll家族</h3><blockquote><p>作用：检测页面滚动的距离</p></blockquote><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220710212619434.png" style="zoom:33%"><ul><li><p>获取宽高</p><ul><li>获取元素的<strong>内容总宽高（不包含滚动条）</strong>返回值不带单位</li><li>scrollWidth 和 scrollHeight</li></ul></li><li><p>获取位置（属性可修改）</p><ul><li>获取元素内容往左、往上滚出去看不到的距离</li><li>scrollLeft和scrollTop</li></ul><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">div.<span class="title function_">addEventListener</span>(<span class="string">&#x27;scroll&#x27;</span>,<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">this</span>.<span class="property">scrollTop</span>)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure><p>注：<code>document.documentElement</code> ：HTML 文档返回对象为HTML元素</p></li></ul><h3 id="offest家族"><a href="#offest家族" class="headerlink" title="offest家族"></a>offest家族</h3><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220710213109240.png" style="zoom:33%"><ul><li>获取宽高<ul><li>获取元素的自身宽高、包含元素自身设置的宽高、padding、border</li><li>offsetWidth 和 offsetHeight</li></ul></li><li>获取位置（只读，不可修改）<ul><li>获取元素距离自己定位父级元素的左、上距离</li></ul></li></ul><h3 id="client家族"><a href="#client家族" class="headerlink" title="client家族"></a>client家族</h3><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220710213252589.png" style="zoom:33%"><ul><li>获取宽高<ul><li>获取元素的可见部分宽高（不包含边框，滚动条等）</li><li>clientWidth和clientHeight</li></ul></li><li>位置<ul><li>clientLeft和clientTop 注意是只读属性</li></ul></li></ul><p><code>resize</code>事件</p><ul><li>改变窗口大小的时候触发的事件，类似css3媒体查询</li></ul><hr><h2 id="Window对象"><a href="#Window对象" class="headerlink" title="Window对象"></a>Window对象</h2><h3 id="BOM"><a href="#BOM" class="headerlink" title="BOM"></a>BOM</h3><blockquote><p>浏览器对象模型</p></blockquote><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220713111536299.png" style="zoom:33%"><ul><li><p>window 是浏览器内置的全局对象，我们所学习的 web apis 的知识内容都是基于 window 对象实现的</p></li><li><p>window 对象下包含了 <code>navigator</code> 、<code>location</code> 、<code>doucment</code> <code>history</code> 、 <code>srceen</code> 5个属性，即 BOM</p></li><li><p>document 是实现 DOM 的基础，它其实是依附于 window 的属性</p></li><li><p>依附于 window 对象的所有属性和方法，使用时可以省略 window</p></li></ul><h3 id="定时器-延时函数"><a href="#定时器-延时函数" class="headerlink" title="定时器-延时函数"></a>定时器-延时函数</h3><blockquote><p>JavaScript 内置的一个用来让代码延迟执行的函数，叫 setTimeout</p></blockquote><p>语法：<code>setTimeout(回调函数,等待的毫秒数)</code></p><p><strong>setTimeout</strong> 仅执行一次，简单来说把一段代码延迟执行</p><p>清除延时函数语法 ：<code>clearTimeout(延时函数的id)</code></p><p>结合函数的递归可以实现 setInterval 间歇函数 一样的功能</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">myInterval</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="keyword">let</span> d=<span class="keyword">new</span> <span class="title function_">date</span>();</span><br><span class="line">    <span class="comment">//写入页面</span></span><br><span class="line">    clock.<span class="property">innertext</span>=d.<span class="title function_">toLocaleString</span>();</span><br><span class="line">    <span class="comment">//调用自己 一直循环，倒计时效果</span></span><br><span class="line">    <span class="built_in">setTimeout</span>(myInterval,<span class="number">1000</span>);  </span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">myInterval</span>();</span><br></pre></td></tr></table></figure><h3 id="JS执行机制-（面试）-star"><a href="#JS执行机制-（面试）-star" class="headerlink" title="JS执行机制 （面试）:star:"></a>JS执行机制 （面试）:star:</h3><blockquote><p>JavaScript 语言的一大特点就是单线程，也就是说，同一个时间只能做一件事。。这是因为 Javascript 这<br>门脚本语言诞生的使命所致——JavaScript 是为处理页面中用户的交互，以及操作 DOM 而诞生的。比<br>如我们对某个 DOM 元素进行添加和删除操作，不能同时进行。 应该先进行添加，之后再删除。</p></blockquote><blockquote><p>单线程就意味着，所有任务需要排队，前一个任务结束，才会执行后一个任务。这样所导致的问<br>题是： 如果 JS 执行的时间过长，这样就会造成页面的渲染不连贯，导致页面渲染加载阻塞的感觉。</p></blockquote><p>同步和异步</p><blockquote><p>为了解决这个问题，利用多核 CPU 的计算能力，HTML5 提出 Web Worker 标准，允许<br>JavaScript 脚本创建多个线程。于是，JS 中出现了同步和异步。</p></blockquote><ul><li><p>同步</p><ul><li>前一个任务执行完才执行后一个任务，程序执行的顺序和代码排列顺序一样</li></ul></li><li><p>异步</p><ul><li><p>执行一个某个任务费很长时间，在做这个任务的同时，还可以去处理其他的任务</p><p>比如：做饭时，等水开的期间可以去其他事，比如切菜</p></li></ul></li><li><p>他们的本质区别： 这条流水线上各个流程的执行顺序不同。</p></li></ul><hr><ul><li><p>同步任务</p><ul><li>同步任务都在主线程上执行，形成一个执行栈。</li></ul></li><li><p>异步任务</p><ul><li><p>JS 的异步是通过回调函数实现的</p></li><li><p>一般来说异步任务有以下三种类型</p><p>1、普通事件，如 click、resize 等<br>2、资源加载，如 load、error 等<br>3、定时器，包括 setInterval、setTimeout 等</p></li><li><p>异步任务相关会添加的任务队列（消息队列）中</p></li></ul></li></ul><hr><p><strong>执行机制</strong></p><ol><li>先执行执行栈里面的同步任务</li><li>异步任务放在消息队列中</li><li>一旦执行栈的执行任务完毕，系统会依次读取消息队列里的异步任务，被读取的异步任务<br>结束等待状态，进入执行栈，开始执行</li></ol><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220713115651765.png" style="zoom:33%"><p><strong>事件循环</strong>（event loop）</p><blockquote><p>由于主线程不断的重复获得任务、执行任务、再获取任务、再执行，所以这种机制被称为事件循环（ event loop）</p></blockquote><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220713115913074.png" style="zoom:33%"><hr><h3 id="location对象"><a href="#location对象" class="headerlink" title="location对象"></a>location对象</h3><blockquote><p>location 的数据类型是对象，它拆分并保存了 URL 地址的各个组成部分</p></blockquote><p><strong>常用属性和方法：</strong></p><ul><li>href 属性获取完整的 URL 地址，对其赋值时用于地址的跳转</li><li>search 属性获取地址中携带的参数，符号 ？后面部分</li><li>hash 属性获取地址中的啥希值，符号 # 后面部分</li><li>reload 方法用来刷新当前页面，传入参数 true 时表示强制刷新</li></ul><p>语法：<code>loaction.属性</code> <code>loactiom.方法()</code></p><h3 id="navigator对象"><a href="#navigator对象" class="headerlink" title="navigator对象"></a>navigator对象</h3><blockquote><p>navigator的数据类型是对象，该对象下记录了浏览器自身的相关信息</p></blockquote><p>常用属性和方法： 通过 userAgent 检测浏览器的版本及平台</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 检测 userAgent（浏览器信息）</span></span><br><span class="line">!(function () &#123;</span><br><span class="line"><span class="type">const</span> <span class="variable">userAgent</span> <span class="operator">=</span> navigator.userAgent</span><br><span class="line"><span class="comment">// 验证是否为Android或iPhone</span></span><br><span class="line"><span class="type">const</span> <span class="variable">android</span> <span class="operator">=</span> userAgent.match(/(Android);?[\s\/]+([\d.]+)?/)</span><br><span class="line"><span class="type">const</span> <span class="variable">iphone</span> <span class="operator">=</span> userAgent.match(/(iPhone\sOS)\s([\d_]+)/)</span><br><span class="line"><span class="comment">// 如果是Android或iPhone，则跳转至移动站点</span></span><br><span class="line"><span class="keyword">if</span> (android || iphone) &#123;</span><br><span class="line">location.href = <span class="string">&#x27;http://m.itcast.cn&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line">&#125;)()</span><br></pre></td></tr></table></figure><h3 id="histroy对象"><a href="#histroy对象" class="headerlink" title="histroy对象"></a>histroy对象</h3><blockquote><p>history 的数据类型是对象，该对象与浏览器地址栏的操作相对应，如前进、后退、历史记录等</p></blockquote><table><thead><tr><th>history对象和方法</th><th>作用</th></tr></thead><tbody><tr><td>back()</td><td>可以后退功能</td></tr><tr><td>forward()</td><td>可以前进功能</td></tr><tr><td>go(参数)</td><td>前进，后退功能，参数决定，-1后退，1前进</td></tr></tbody></table><h3 id="本地存储"><a href="#本地存储" class="headerlink" title="本地存储"></a>本地存储</h3><blockquote><p>随着互联网的快速发展，基于网页的应用越来越普遍，同时也变的越来越复杂，为了满足各种各样的需求，会经常性在<br>本地存储大量的数据，HTML5规范提出了相关解决方案</p></blockquote><ol><li>数据存储在用户浏览器中</li><li>设置、读取方便、甚至页面刷新不丢失数据</li><li>容量较大，sessionStorage和localStorage约 5M 左右</li></ol><p><strong>localStorage</strong></p><ol><li>生命周期永久生效，除非手动删除 否则关闭页面也会存在</li><li>可以多窗口（页面）共享（同一浏览器可以共享）</li><li>以键值对的形式存储使用</li></ol><p>语法</p><ul><li>存储数据：<code>localStorage.setItem(key, value)</code></li><li>获取数据：<code>localStorage.getItem(key)</code></li><li>删除数据：<code>localStorage.removeItem(key)</code></li></ul><p>存储复杂数据类型存储：</p><blockquote><p>本地只能存储字符串,无法存储复杂数据类型.需要将复杂数据类型转换成JSON字符串,在存储到本地</p></blockquote><p><strong>JSON.stringify(复杂数据类型) ：</strong></p><p>将复杂数据转换成JSON字符串 <strong>存储</strong> 本地存储中</p><p><strong>JSON.parse(JSON字符串)：</strong></p><p>将JSON字符串转换成对象 <strong>取出</strong> 时候使用</p><hr><p>sessionStorage（了解）<br>1. 生命周期为关闭浏览器窗口<br>2. 在同一个窗口(页面)下数据可以共享<br>3. 以键值对的形式存储使用<br>4. 用法跟localStorage 基本相同</p><h3 id="自定义属性"><a href="#自定义属性" class="headerlink" title="自定义属性"></a>自定义属性</h3><p>固有属性：</p><blockquote><p>标签天生自带的属性 比如class id title等, 可以直接使用点语法操作</p></blockquote><p>自定义属性:</p><blockquote><p>由程序员自己添加的属性,在DOM对象中找不到, 无法使用点语法操作,必须使用专门的API</p></blockquote><ul><li>获取自定义属性 ：<code>getAttribute(&#39;属性名&#39;)</code></li><li>设置自定义属性：<code>setAttribute(&#39;属性名&#39;, &#39;属性值&#39;)</code></li><li>删除自定义属性：<code>removeAttribute(&#39;属性名&#39;)</code></li></ul><p>data-自定义属性：</p><blockquote><p>传统的自定义属性没有专门的定义规则,开发者随意定值,不够规范,所以在html5中推出来了专门的data-自定义属性 在标签上一律以data-开头</p></blockquote><p>在DOM对象上一律以dataset对象方式获取</p><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220713122248633.png" style="zoom:33%"><hr><h2 id="正则表达式"><a href="#正则表达式" class="headerlink" title="正则表达式"></a>正则表达式</h2><blockquote><p>正则表达式（Regular Expression）是用于匹配字符串中字符组合的模式。在 JavaScript中，正则表达式也是对象</p></blockquote><p>正则表达式在 JavaScript中的使用场景：</p><ul><li>例如验证表单：用户名表单只能输入英文字母、数字或者下划线， 昵称输入框中可以输入中文(匹配)</li><li>比如用户名: <code>/^[a-z0-9_-]&#123;3,16&#125;$/</code></li><li>过滤掉页面内容中的一些敏感词(替换)，或从字符串中获取我们想要的特定部分(提取)等 。</li></ul><h3 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h3><p><strong>使用</strong>：</p><ol><li>定义规则</li><li>查找</li></ol><p><strong>语法</strong>：<code>let 变量名=/表达式/</code></p><ul><li>&#x2F; &#x2F; 是正则表达式字面量，比如 ：<code>let reg=/abc/</code></li></ul><p><strong>判断</strong>：</p><ul><li><p>test() 方法 用来查看正则表达式与指定的字符串是否匹配 ，返回 false 或 true</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> str = <span class="string">&#x27;hello ,world&#x27;</span></span><br><span class="line"><span class="keyword">let</span> reg = <span class="regexp">/hello/</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(reg.<span class="title function_">test</span>(str))  <span class="comment">//true</span></span><br></pre></td></tr></table></figure></li><li><p>exec() 方法 在一个指定字符串中执行一个搜索匹配</p><p>如果匹配成功，exec() 方法返回一个数组，否则返回null</p></li></ul><h3 id="元字符"><a href="#元字符" class="headerlink" title="元字符"></a>元字符</h3><blockquote><p>是一些具有特殊含义的字符，可以极大提高了灵活性和强大的匹配功能。</p></blockquote><ul><li><p>比如，规定用户只能输入英文26个英文字母，普通字符的话 abcdefghijklm…..</p><p>但是换成元字符写法： [a-z]</p></li></ul><p><strong>方便记忆和学习，众多的元字符进行了分类：</strong></p><ol><li><p><strong>边界符</strong>（表示位置，开头和结尾，必须用什么开头，用什么结尾）</p><p>正则表达式中的边界符（位置符）用来提示字符所处的位置，主要有两个字符</p><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220714135805923.png" style="zoom:50%"><p><strong>注意</strong>：如果 <code>^</code> 和 <code>$</code>在一起，表示必须是精确匹配。</p></li><li><p><strong>量词</strong> （表示重复次数）</p><p>量词用来 设定某个模式出现的次数</p><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220714135915669.png" style="zoom:50%"><p><strong>注意</strong>： 逗号左右两侧千万不要出现空格</p></li><li><p><strong>字符类</strong> （比如 <code>\d</code> 表示 0~9）</p><ul><li><p><input disabled type="checkbox"> <code>-</code> 连字符</p><p>使用连字符 <code>-</code> 表示一个范围</p></li><li><p><input disabled type="checkbox"> 比如：</p><ol><li>[a-z] 表示 a 到 z 26个英文字母都可以</li><li>[a-zA-Z] 表示大小写都可以</li><li>[0-9] 表示 0~9 的数字都可以</li></ol></li><li><p><input disabled type="checkbox"> [ ] 里面加上 <code>^</code> 取反符号<br>比如：<br><code>[^a-z]</code> 匹配除了小写字母以外的字符<br>注意要写到中括号里面</p></li><li><p><input disabled type="checkbox"> <code>.</code> 匹配除换行符之外的任何单个字符</p></li><li><p><input disabled type="checkbox"> 预定义：指的是某些常见模式的简写方式</p></li></ul><img src="" data-lazy-src="https://picgo-fantasy06.oss-cn-guangzhou.aliyuncs.com/img/image-20220714140426304.png" style="zoom:50%"></li><li><p><strong>修饰符</strong></p><p>修饰符约束正则执行的某些细节行为，如是否区分大小写、是否支持多行匹配等</p><p>语法：</p><p><code>/表达式/修饰符</code></p><p>i 是单词 ignore 的缩写，正则匹配时字母不区分大小写<br>g 是单词 global 的缩写，匹配所有满足正则表达式的结果</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="regexp">/a/i</span>.<span class="title function_">test</span>(<span class="string">&#x27;a&#x27;</span>))  <span class="comment">//true</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="regexp">/a/i</span>.<span class="title function_">test</span>(<span class="string">&#x27;A&#x27;</span>))  <span class="comment">//true</span></span><br></pre></td></tr></table></figure><p>替换 replace 替换：（过滤敏感词）</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">字符串.<span class="title function_">replace</span>(<span class="regexp">/正则表达式/</span>，<span class="string">&#x27;替换的文本&#x27;</span>)</span><br></pre></td></tr></table></figure></li></ol></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">本文作者:</span> <span class="post-copyright-info"><a href="https://www.webxc.ml">XC's Blog</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">本文链接:</span> <span class="post-copyright-info"><a href="https://www.webxc.ml/post/sr32/">https://www.webxc.ml/post/sr32/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明:</span> <span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.webxc.ml" target="_blank">XC's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Web-APIs%E7%AC%94%E8%AE%B0/">Web APIs笔记</a></div><div class="post_share"><div class="social-share" data-image="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://npm.elemecdn.com/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload='this.media="all"'><script src="https://npm.elemecdn.com/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.png" target="_blank"><img class="post-qr-code-img" src="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.png" alt="Wechat"></a><div class="post-qr-code-desc">Wechat</div></li><li class="reward-item"><a href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/alipay.jpg" target="_blank"><img class="post-qr-code-img" src="https://npm.elemecdn.com/webxc@1.0.0/lxfs/alipay.jpg" alt="Alipay"></a><div class="post-qr-code-desc">Alipay</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/post/fa31/"><img class="prev-cover" src="https://npm.elemecdn.com/webxc/cover/js1.webp" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇文章</div><div class="prev_info">ES6模块化与异步编程</div></div></a></div><div class="next-post pull-right"><a href="/post/ce68/"><img class="next-cover" src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="cover of next post"><div class="pagination-info"><div class="label">下一篇文章</div><div class="next_info">Web APIs第一天</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/post/fa31/" title="ES6模块化与异步编程"><img class="cover" src="https://npm.elemecdn.com/webxc/cover/js1.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">ES6模块化与异步编程</div></div></a></div><div><a href="/post/ce68/" title="Web APIs第一天"><img class="cover" src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-15</div><div class="title">Web APIs第一天</div></div></a></div><div><a href="/post/ar34/" title="Web APIs第七天"><img class="cover" src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-04-17</div><div class="title">Web APIs第七天</div></div></a></div></div></div><hr><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i> <span>评论</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="avatar"></div><div class="author-info__name">XC's Blog</div><div class="author-info__description">XC's Blog 记录生活和学习文章</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">74</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">22</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">22</div></a></div><div class="card-info-social-icons is-center"><a class="social-icon" href="https://tenapi.cn/qqzlk/?qq=2848141597" target="_blank" title="QQ"><i class="iconfont icon-QQ"></i></a><a class="social-icon" href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.jpg" target="_blank" title="微信"><i class="iconfont icon-weixin"></i></a><a class="social-icon" href="https://github.com/web-xc" target="_blank" title="Github"><i class="iconfont icon-github"></i></a><a class="social-icon" href="https://space.bilibili.com/2134826455" target="_blank" title="BiliBili"><i class="iconfont icon-bilibili"></i></a><a class="social-icon" href="https://music.163.com/#/user/home?id=323682437" target="_blank" title="网易云音乐"><i class="iconfont icon-wyy"></i></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#WebAPIs%E5%9F%BA%E6%9C%AC%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0"><span class="toc-number">1.</span> <span class="toc-text">WebAPIs基本学习笔记</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#DOM%E7%9A%84%E5%86%85%E5%AE%B9"><span class="toc-number">2.</span> <span class="toc-text">DOM的内容</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#DOM%E6%A0%91"><span class="toc-number">3.</span> <span class="toc-text">DOM树</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96DOM%E5%85%83%E7%B4%A0"><span class="toc-number">4.</span> <span class="toc-text">获取DOM元素</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%AE%BE%E7%BD%AE%E5%92%8C%E4%BF%AE%E6%94%B9DOM%E5%85%83%E7%B4%A0"><span class="toc-number">5.</span> <span class="toc-text">设置和修改DOM元素</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%AE%BE%E7%BD%AE%E4%B8%8E%E4%BF%AE%E6%94%B9DOM%E5%85%83%E7%B4%A0%E7%9A%84%E5%B1%9E%E6%80%A7"><span class="toc-number">6.</span> <span class="toc-text">设置与修改DOM元素的属性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E8%A1%A8%E5%8D%95%E5%B1%9E%E6%80%A7"><span class="toc-number">7.</span> <span class="toc-text">修改表单属性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9A%E6%97%B6%E5%99%A8-setInterval-%E9%97%B4%E6%AD%87%E5%87%BD%E6%95%B0"><span class="toc-number">8.</span> <span class="toc-text">定时器-setInterval() 间歇函数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8B%E4%BB%B6"><span class="toc-number">9.</span> <span class="toc-text">事件</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8B%E4%BB%B6%E7%9B%91%E5%90%AC"><span class="toc-number">9.1.</span> <span class="toc-text">事件监听</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%89%88%E6%9C%AC"><span class="toc-number">9.2.</span> <span class="toc-text">版本</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8B%E4%BB%B6%E7%B1%BB%E5%9E%8B"><span class="toc-number">9.3.</span> <span class="toc-text">事件类型</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%AB%98%E9%98%B6%E5%87%BD%E6%95%B0"><span class="toc-number">10.</span> <span class="toc-text">高阶函数</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%87%BD%E6%95%B0%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="toc-number">10.1.</span> <span class="toc-text">函数表达式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9B%9E%E8%B0%83%E5%87%BD%E6%95%B0"><span class="toc-number">10.2.</span> <span class="toc-text">回调函数</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F"><span class="toc-number">11.</span> <span class="toc-text">环境变量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BC%96%E7%A8%8B%E6%80%9D%E6%83%B3"><span class="toc-number">12.</span> <span class="toc-text">编程思想</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8E%92%E4%BB%96%E6%80%9D%E6%83%B3"><span class="toc-number">12.1.</span> <span class="toc-text">排他思想</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#DOM%E7%BB%93%E7%82%B9"><span class="toc-number">13.</span> <span class="toc-text">DOM结点</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BB%93%E7%82%B9%E7%9A%84%E6%9F%A5%E6%89%BE"><span class="toc-number">13.1.</span> <span class="toc-text">结点的查找</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BB%93%E7%82%B9%E7%9A%84%E5%A2%9E%E5%8A%A0"><span class="toc-number">13.2.</span> <span class="toc-text">结点的增加</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BB%93%E7%82%B9%E7%9A%84%E5%85%8B%E9%9A%86"><span class="toc-number">13.3.</span> <span class="toc-text">结点的克隆</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BB%93%E7%82%B9%E7%9A%84%E5%88%A0%E9%99%A4"><span class="toc-number">13.4.</span> <span class="toc-text">结点的删除</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%87%8D%E7%BB%98%E5%92%8C%E5%9B%9E%E6%B5%81"><span class="toc-number">14.</span> <span class="toc-text">重绘和回流</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9B%9E%E6%B5%81-%E9%87%8D%E6%8E%92"><span class="toc-number">14.1.</span> <span class="toc-text">回流(重排)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%87%8D%E7%BB%98"><span class="toc-number">14.2.</span> <span class="toc-text">重绘</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8B%E4%BB%B6%E9%AB%98%E7%BA%A7"><span class="toc-number">15.</span> <span class="toc-text">事件高级</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8B%E4%BB%B6%E5%AF%B9%E8%B1%A1"><span class="toc-number">15.1.</span> <span class="toc-text">事件对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8B%E4%BB%B6%E6%B5%81"><span class="toc-number">15.2.</span> <span class="toc-text">事件流</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8B%E4%BB%B6%E5%A7%94%E6%89%98"><span class="toc-number">15.3.</span> <span class="toc-text">事件委托</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%BB%9A%E5%8A%A8%E4%BA%8B%E4%BB%B6"><span class="toc-number">16.</span> <span class="toc-text">滚动事件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8A%A0%E8%BD%BD%E4%BA%8B%E4%BB%B6"><span class="toc-number">17.</span> <span class="toc-text">加载事件</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#load-%E4%BA%8B%E4%BB%B6"><span class="toc-number">17.1.</span> <span class="toc-text">load 事件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#DOMContentLoaded"><span class="toc-number">17.2.</span> <span class="toc-text">DOMContentLoaded</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%83%E7%B4%A0%E5%A4%A7%E5%B0%8F%E5%92%8C%E4%BD%8D%E7%BD%AE"><span class="toc-number">18.</span> <span class="toc-text">元素大小和位置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#scroll%E5%AE%B6%E6%97%8F"><span class="toc-number">18.1.</span> <span class="toc-text">scroll家族</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#offest%E5%AE%B6%E6%97%8F"><span class="toc-number">18.2.</span> <span class="toc-text">offest家族</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#client%E5%AE%B6%E6%97%8F"><span class="toc-number">18.3.</span> <span class="toc-text">client家族</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Window%E5%AF%B9%E8%B1%A1"><span class="toc-number">19.</span> <span class="toc-text">Window对象</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#BOM"><span class="toc-number">19.1.</span> <span class="toc-text">BOM</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%9A%E6%97%B6%E5%99%A8-%E5%BB%B6%E6%97%B6%E5%87%BD%E6%95%B0"><span class="toc-number">19.2.</span> <span class="toc-text">定时器-延时函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#JS%E6%89%A7%E8%A1%8C%E6%9C%BA%E5%88%B6-%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89-star"><span class="toc-number">19.3.</span> <span class="toc-text">JS执行机制 （面试）:star:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#location%E5%AF%B9%E8%B1%A1"><span class="toc-number">19.4.</span> <span class="toc-text">location对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#navigator%E5%AF%B9%E8%B1%A1"><span class="toc-number">19.5.</span> <span class="toc-text">navigator对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#histroy%E5%AF%B9%E8%B1%A1"><span class="toc-number">19.6.</span> <span class="toc-text">histroy对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9C%AC%E5%9C%B0%E5%AD%98%E5%82%A8"><span class="toc-number">19.7.</span> <span class="toc-text">本地存储</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B1%9E%E6%80%A7"><span class="toc-number">19.8.</span> <span class="toc-text">自定义属性</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="toc-number">20.</span> <span class="toc-text">正则表达式</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AF%AD%E6%B3%95"><span class="toc-number">20.1.</span> <span class="toc-text">语法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%83%E5%AD%97%E7%AC%A6"><span class="toc-number">20.2.</span> <span class="toc-text">元字符</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/post/us87/" title="JS进阶第二天"><img src="https://npm.elemecdn.com/webxc/cover/js1.webp" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="JS进阶第二天"></a><div class="content"><a class="title" href="/post/us87/" title="JS进阶第二天">JS进阶第二天</a><time datetime="2023-05-05T01:20:00.000Z" title="发表于 2023-05-05 01:20:00">2023-05-05</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/re67/" title="JS进阶第一天"><img src="https://npm.elemecdn.com/webxc/cover/js1.webp" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="JS进阶第一天"></a><div class="content"><a class="title" href="/post/re67/" title="JS进阶第一天">JS进阶第一天</a><time datetime="2023-04-26T16:30:00.000Z" title="发表于 2023-04-26 16:30:00">2023-04-26</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/ar34/" title="Web APIs第七天"><img src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="Web APIs第七天"></a><div class="content"><a class="title" href="/post/ar34/" title="Web APIs第七天">Web APIs第七天</a><time datetime="2023-04-17T20:00:00.000Z" title="发表于 2023-04-17 20:00:00">2023-04-17</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2023 By XC's Blog</div><div class="framework-info"><span></span> <a target="_blank" rel="noopener" href="https://icp.gov.moe/?keyword=20235221">萌ICP备20235221号</a><span class="footer-separator">|</span><span></span> <a target="_blank" rel="noopener" href="https://icp.gov.moe/">萌ICP查询</a><div id="running-time"></div></div><script>setInterval((()=>{let e=Math.round(new Date("2021-11-21 01:35:06").getTime()/1e3),t=Math.round(((new Date).getTime()+288e5)/1e3)-e,n=new Array(0,0,0,0,0);t>=31536e3&&(n[0]=parseInt(t/31536e3),t%=31536e3),t>=86400&&(n[1]=parseInt(t/86400),t%=86400),t>=3600&&(n[2]=parseInt(t/3600),t%=3600),t>=60&&(n[3]=parseInt(t/60),t%=60),t>0&&(n[4]=t),currentTimeHtml="本站已安全运行 "+n[0]+" 年 "+n[1]+" 天 "+n[2]+" 时 "+n[3]+" 分 "+n[4]+" 秒",document.getElementById("running-time").innerHTML=currentTimeHtml}),1e3)</script></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i><span id="percent">0<span>%</span></span></button><button id="go-down" type="button" title="直达底部" onclick="btf.scrollToDest(document.body.scrollHeight,500)"><i class="fas fa-arrow-down"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i> <span>正在载入文件,请稍后</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"></div></div><hr><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="https://npm.elemecdn.com/hexo-theme-butterfly/source/js/utils.js"></script><script src="https://npm.elemecdn.com/hexo-theme-butterfly@4.4.0/source/js/main.js"></script><script src="https://npm.elemecdn.com/@fancyapps/ui/dist/fancybox.umd.js"></script><script src="https://npm.elemecdn.com/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://npm.elemecdn.com/node-snackbar/dist/snackbar.min.js"></script><script src="https://npm.elemecdn.com/hexo-theme-butterfly/source/js/search/local-search.js"></script><div class="js-pjax"><script>(()=>{const e=document.querySelectorAll("#article-container .mermaid-wrap");if(e.length){window.runMermaid=()=>{window.loadMermaid=!0;const t="dark"===document.documentElement.getAttribute("data-theme")?"dark":"default";Array.from(e).forEach(((e,n)=>{const d=e.firstElementChild,r="mermaid-"+n,m="%%{init:{ 'theme':'"+t+"'}}%%\n"+d.textContent;mermaid.mermaidAPI.render(r,m,(e=>{d.insertAdjacentHTML("afterend",e)}))}))};const t=()=>{window.loadMermaid?runMermaid():getScript("https://npm.elemecdn.com/mermaid/dist/mermaid.min.js").then(runMermaid)};window.pjax?t():document.addEventListener("DOMContentLoaded",t)}})()</script><script>(()=>{const o=()=>{twikoo.init(Object.assign({el:"#twikoo-wrap",envId:"https://blog2.webxc.ml/",region:"",onCommentLoaded:function(){btf.loadLightbox(document.querySelectorAll("#twikoo .tk-content img:not(.tk-owo-emotion)"))}},null))},t=()=>{"object"!=typeof twikoo?getScript("https://npm.elemecdn.com/twikoo@1.6.10/dist/twikoo.all.min.js").then(o):setTimeout(o,0)};t()})()</script></div><script data-pjax="true" defer src="https://npm.elemecdn.com/webxc@1.0.16/css/style.js"></script><script defer src="https://npm.elemecdn.com/hexo-theme-butterfly@4.4.0/source/js/search/local-search.js"></scrip><script src="https://npm.elemecdn.com/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful=!0,POWERMODE.shake=!0,POWERMODE.mobile=!0,document.body.addEventListener("input",POWERMODE)</script><script src="https://npm.elemecdn.com/pjax@0.2.8/pjax.min.js"></script><script>let pjaxSelectors=["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax",".tk-comments-container"];var pjax=new Pjax({elements:'a:not([target="_blank"])',selectors:pjaxSelectors,cacheBust:!1,analytics:!1,scrollRestoration:!1});document.addEventListener("pjax:send",(function(){if(window.tocScrollFn&&window.removeEventListener("scroll",window.tocScrollFn),window.scrollCollect&&window.removeEventListener("scroll",scrollCollect),"object"==typeof preloader&&preloader.initLoading(),document.getElementById("rightside").style.cssText="opacity: ''; transform: ''",window.aplayers)for(let e=0;e<window.aplayers.length;e++)window.aplayers[e].options.fixed||window.aplayers[e].destroy();"object"==typeof typed&&typed.destroy();const e=document.body.classList;e.contains("read-mode")&&e.remove("read-mode"),"object"==typeof disqusjs&&disqusjs.destroy()})),document.addEventListener("pjax:complete",(function(){window.refreshFn(),document.querySelectorAll("script[data-pjax]").forEach((e=>{const t=document.createElement("script"),o=e.text||e.textContent||e.innerHTML||"";Array.from(e.attributes).forEach((e=>t.setAttribute(e.name,e.value))),t.appendChild(document.createTextNode(o)),e.parentNode.replaceChild(t,e)})),GLOBAL_CONFIG.islazyload&&window.lazyLoadInstance.update(),"function"==typeof chatBtnFn&&chatBtnFn(),"function"==typeof panguInit&&panguInit(),"function"==typeof gtag&&gtag("config","",{page_path:window.location.pathname}),"object"==typeof _hmt&&_hmt.push(["_trackPageview",window.location.pathname]),"function"==typeof loadMeting&&document.getElementsByClassName("aplayer").length&&loadMeting(),"object"==typeof Prism&&Prism.highlightAll(),"object"==typeof preloader&&preloader.endLoading()})),document.addEventListener("pjax:error",(e=>{404===e.request.status&&pjax.loadUrl("/404.html")}))</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script data-pjax>function butterfly_swiper_injector_config(){var s=document.getElementById("recent-posts");console.log("已挂载butterfly_swiper"),s.insertAdjacentHTML("afterbegin",'<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-04-11</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fr67/&quot;);" href="javascript:void(0);" alt="">Web APIs第六天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-02-16</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fd38/&quot;);" href="javascript:void(0);" alt="">JavaScript 第五天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-02-07</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/7f86/&quot;);" href="javascript:void(0);" alt="">JavaScript 第四天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-12-27</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/6e+47/&quot;);" href="javascript:void(0);" alt="">JavaScript 第三天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover15.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-10-31</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/2db5/&quot;);" href="javascript:void(0);" alt="">移动开发-Flex布局</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover16.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-11-14</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/1c7e/&quot;);" href="javascript:void(0);" alt="">移动开发-媒体查询</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover17.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-11-17</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/7fc/&quot;);" href="javascript:void(0);" alt="">移动开发-响应式</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.11/cover/css5.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-10-16</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/d97/&quot;);" href="javascript:void(0);" alt="">CSS-2D-3D转换</a><div class="blog-slider__text">点击查看</div></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div></div></div>')}for(var elist="null".split(","),cpage=location.pathname,epage="all",flag=0,i=0;i<elist.length;i++)cpage.includes(elist[i])&&flag++;("all"===epage&&0==flag||epage===cpage)&&butterfly_swiper_injector_config()</script><script defer src="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper.min.js"></script><script defer data-pjax src="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper_init.js"></script></body></html>